<?php
	/**
	 * The loop that displays posts.
	 *
	 * The loop displays the posts and the post content.  See
	 * http://codex.wordpress.org/The_Loop to understand it and
	 * http://codex.wordpress.org/Template_Tags to understand
	 * the tags used in it.
	 *
	 * This can be overridden in child themes with loop.php or
	 * loop-template.php, where 'template' is the loop context
	 * requested by a template. For example, loop-index.php would
	 * be used if it exists and we ask for the loop with:
	 * <code>get_template_part( 'loop', 'index' );</code>
	 *
	 * @package WordPress
	 * @subpackage Master Theme
	 */
?>
                
    <?php /** Start the Loop **/
    while ( have_posts() ) : the_post(); ?>

        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        	
            <?php
			global $current_user;
			get_currentuserinfo();
			if ( is_user_logged_in() && current_user_can('edit_posts') || $current_user->ID == $post->post_author ) { ?>
            
            <p class="page-title"><?php the_title(); ?></p>

            <div class="entry-content">
                <?php the_content(); ?>
                <h3>Submitted Documents:</h3>
                <?php
					$args = array(
						'post_type' => 'attachment',
						'numberposts' => null,
						'post_status' => null,
						'post_parent' => $post->ID
					); 
					$attachments = get_posts($args);
					if ($attachments) {
						foreach ($attachments as $attachment) {
							echo '<a href="' . str_replace('/home/webadmin/trudocs.com/html', 'http://trudocs.com', get_attached_file($attachment->ID)) . '">';
							echo str_replace('/home/webadmin/trudocs.com/html', 'http://trudocs.com', get_attached_file($attachment->ID));
							echo '</a><br />';
						}
					}
				?>
            </div><!-- .entry-content -->
            
            <?php } else { ?>
            	<h1>This page is restricted.</h1>
                <p>Please %s to view this page. <?php echo wp_loginout( '', false ); ?></p>
                <p>Or try browsing our <a href="<?php echo site_url('members'); ?>">Short Sale Assistants.</a></p>
			<?php } ?>

        </div><!-- #post-## -->

    <?php endwhile; // End the loop. Whew. ?>
    